home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_02_10
/
2n10038a
< prev
next >
Wrap
Text File
|
1991-08-25
|
35KB
|
1,197 lines
Page 60,132
;---------------------------------------------------------------
; BEGIN LISTING 2
;---------------------------------------------------------------
;
; 386LOAD.ASM Copyright (c) 1991 Robert Collins
;
; This program demonstrates various aspects of CPU
; behavior that become apparent when using LOADALL.
;
; Test 1: Checks that LOADALL loads all the general-
; purpose registers; loads the segment registers
; with values that are inconsistant to their
; respective descriptor cache registers.
;
; Test 2: Access extended memory in real mode.
;
; Test 3: Tests that the Present bit in a descriptor
; table can be loaded using LOADALL without
; generating exception 11. But when the segment
; is accessed, exception 13 is generated.
; NOTE: This test should be done in protected
; mode, but can be done in real mode. 1) In real
; mode, no error code is pushed on the stack
; (possibly due to a bug in the CPU). 2) Also,
; when this test is executed in real-mode, the
; '386 fails to set the Present bit when the
; segment is subsequently loaded. This latter
; condition is clearly a bug in the '386.
;
; Test 4: Test 32-bit protected mode.
;
; Test 5: Test 32-bit real mode -- a mode that is an
; illegal mode for the CPU.
;
; Test 6: Test that the Granularity bit in the descriptor
; cache register has no affect on the segment
; limit field.
;
; Test 7: Test execution breakpoints.
;
; Test 8: Test data breakpoints.
;
; This program was written for Microsoft MASM 5.1.
; This program contains compiler directives and branching
; techniques that might not be available on previous
; versions of the Macro Assembler, nor in competitive
; products.
;
;---------------------------------------------------------------
;---------------------------------------------------------------
; Compiler directives
;---------------------------------------------------------------
Title LOADALL_386
.radix 16
.8086
;---------------------------------------------------------------
; Interrupt vector segment
;---------------------------------------------------------------
ABS0 segment at 0
org 6*4
INT_6 dd ?
ABS0 ends
;---------------------------------------------------------------
; Structure definitions
;---------------------------------------------------------------
Desc_cache STRUC
db 0
_Type db ?
_CS32 db 0
db 0
_Addr dd ?
_Limit dd ?
Desc_cache ENDS
Loadall_struc STRUC
_Cr0 dd 0
_Eflags dd 2
_Eip dd 0
_Edi dd 66666666h
_Esi dd 77777777h
_Ebp dd 55555555h
_Esp dd 88888888h
_Ebx dd 22222222h
_Edx dd 44444444h
_Ecx dd 33333333h
_Eax dd 11111111h
_Dr6 dd 0
_Dr7 dd 0
_Tr dd 0
_Ldt dd 0
_Gs dd 5555h
_Fs dd 4444h
_Ds dd 2222h
_Ss dd 6666h
_Cs dd 1111h
_Es dd 3333h
TSS_Desc dd 00008900h,00070000h,00000800h
IDT_Desc dd 00000000h,00000000h,000003ffh
Gdt_Desc dd 00000000h,00000000h,00000000h
Ldt_Desc dd 00008200h,00090000h,00000088h
GS_Desc dd 00009300h,00050000h,0000ffffh
FS_Desc dd 00009300h,00040000h,0000ffffh
DS_Desc dd 00009300h,00020000h,0000ffffh
SS_Desc dd 00009300h,00060000h,0000ffffh
CS_Desc dd 00009b00h,00000000h,0000ffffh
ES_Desc dd 00009300h,00030000h,00fffffch
Loadall_Struc ENDS
Descriptor STRUC
Seg_limit dw ? ; Segment limit
Base_A15_A00 dw ? ; A00..A15 of base address
Base_A23_A16 db ? ; A16..A23 of base address
Access_rights db ? ; Segment access rights
Limit_A19_A16 db ? ; Granularity, Op-size,
; Limit A16..A19
Base_A31_A24 db ? ; A24..A31 of base address
Descriptor ENDS
INT_Desc STRUC
IGate_Offset dw ? ; Offset of handler
CSEG_Sel dw ? ; Code segment selector
db 0
db 86h ; 286 interrupt gate=16bit
; CS:IP, FLAGS
Resvd dw 0 ; Reserved=0
INT_Desc ENDS
;-----------------------------------------------------------------------------
; Macro definitions
;-----------------------------------------------------------------------------
Init_descriptor macro segment,offset,desc_name
push ax
push dx
push si
push es
mov ax,&segment ;; get segment name
mov es,ax ;; to form 24 bit address
mov si,&offset ;;
mov ax,es ; point to control block
xor dh,dh ; clear upper register
mov dl,ah ; build high byte of 32-bit address
shr dl,4 ; use only high nibble from (AX)
shl ax,4 ; strip high nibble from segment
add ax,si ; add the GDT offset to develop low word
adc dx,0 ; adjust high byte if carry from low
mov &desc_name.Base_A15_A00,ax ;; low word of address
mov &desc_name.Base_A23_A16,dl ;; high byte of address
mov &desc_name.Base_A31_A24,dh ;; high byte of linear address
pop es
pop si
pop dx
pop ax
endm
FARJMP MACRO destination,selector ; dynamic JMP FAR SEG:OFF
db 0eah ;; jmp instruction
dw offset destination ;; offset word
dw selector ;; segment selector word
endm
LONGJMP MACRO destination,selector ; dynamic JMP FAR SEG:OFF
db 0eah ;; jmp instruction
dd offset destination ;; offset word
dw selector ;; segment selector word
endm
IO_DELAY MACRO
out 0edh,ax
endm
LOADALL MACRO
db 0fh,07h
ENDM
PRINT_STRING MACRO MSG_NAME
mov ah,9
mov dx,offset MSG_NAME
int 21h
ENDM
_DATA SEGMENT PARA PUBLIC 'DATA'
;---------------------------------------------------------------
; Equates & local variables
;---------------------------------------------------------------
; Protected mode access rights
;---------------------------------------------------------------
CS_access equ 10011011b
DS_access equ 10010011b
;---------------------------------------------------------------
; Text equates
;---------------------------------------------------------------
CRLF equ <0dh,0ah>
CRLF$ equ <CRLF,'$'>
INT6 equ [bp-4]
;---------------------------------------------------------------
; Loadall table(s)
;---------------------------------------------------------------
Loadall_tbl Loadall_struc <>
Machine_State Loadall_struc <>
;---------------------------------------------------------------
; Global Descriptor Table
;---------------------------------------------------------------
GDT_386 Descriptor <Gdt3_len-1,,,DS_access>
CSEG3 Descriptor <0ffffh,0,0,CS_access>
DSEG3 Descriptor <0ffffh,0,20h,DS_access>
Gdt3_len equ $-Gdt_386
;---------------------------------------------------------------
; Interrupt Descriptor Table
;---------------------------------------------------------------
IDT_386 INT_Desc <Offset INT13,CSEG3-GDT_386> ; INT00
INT_Desc <Offset INT01,CSEG3-GDT_386> ; INT01
INT_Desc <Offset INT13,CSEG3-GDT_386> ; INT02
INT_Desc <Offset INT13,CSEG3-GDT_386> ; INT03
INT_Desc <Offset INT13,CSEG3-GDT_386> ; INT04
INT_Desc <Offset INT13,CSEG3-GDT_386> ; INT05
INT_Desc <Offset INT13,CSEG3-GDT_386> ; INT06
INT_Desc <Offset INT13,CSEG3-GDT_386> ; INT07
INT_Desc <Offset INT13,CSEG3-GDT_386> ; INT08
INT_Desc <Offset INT13,CSEG3-GDT_386> ; INT09
INT_Desc <Offset INT13,CSEG3-GDT_386> ; INT0a
INT_Desc <Offset INT13,CSEG3-GDT_386> ; INT0b
INT_Desc <Offset INT13,CSEG3-GDT_386> ; INT0c
INT_Desc <Offset INT13,CSEG3-GDT_386> ; INT0d
IDT3_Len equ $-IDT_386
;---------------------------------------------------------------
; Misc. local variables
;---------------------------------------------------------------
Mem_buffer db 400h dup (0) ; Store 2M mem.
Buffer db 40h dup (0)
Buffer2 dw 10h dup (0)
RM_IDT3_Ptr dw (256d*4)-1 ; Real-mode IDT
dd 0 ; pointer
dw 0
;---------------------------------------------------------------
; String Messages
;---------------------------------------------------------------
Passed db " PASSED.",CRLF$
Failed db "--> FAILED <--",CRLF$
Not_386 db "Not 80386 class computer.",CRLF$
Rmvd db "LOADALL removed from 80386 mask.",CRLF$
RFail db "Registers weren't loaded correctly."
LF db CRLF$
;